home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-10-14 | 4.6 KB | 192 lines | [TEXT/MMCC] |
- //---------------------------------------------------------------------
- //---------------------------------------------------------------------
- //
- // Horrible Rickety Shell, by Dave Johnson
- //
- // © Copyright 1985 - 1994 Anyone Who Wants It,
- // All Rights Energetically Heaved as far away from me as possible.
- // Use at your own (considerable) risk.
-
-
- #include "Shell.h"
- #include <Traps.h>
-
- extern Boolean doneflag;
-
- /* These are stolen from arith.c, so we don't have to include the ANSI library for
- 2 routines
- int
- abs(int i)
- {
- if (i < 0)
- return(-i);
- return(i);
- }
-
-
- long
- labs(long i)
- {
- if (i < 0)
- return(-i);
- return(i);
- }
- */
-
- /****************************************************
- Quickdraw Things...
- *****************************************************/
-
- /*------------------------------------------------------------------------
- NewPixImage() Creates pix image and inits the fields of the pixmap...
- ------------------------------------------------------------------------*/
-
- Boolean NewPixImage(PixMapHandle ThePix, Rect *TheRect, short dpth)
- {
- Ptr ThePtr;
- long Offrowbytes, ptrsize;
-
- Offrowbytes =(((dpth * (TheRect->right - TheRect->left)) + 15) / 16) * 2;
- ptrsize = (TheRect->bottom - TheRect->top) * Offrowbytes;
- ThePtr = NewPtr(ptrsize);
- if(MemError() != noErr)
- return(false);
-
- (**ThePix).baseAddr = ThePtr;
- (**ThePix).rowBytes = Offrowbytes + 0x8000;
- (**ThePix).bounds = *TheRect;
- (**ThePix).pixelSize = dpth;
- (**ThePix).cmpCount = 1;
- (**ThePix).cmpSize = dpth;
- return(true);
- }
-
-
- /*------------------------------------------------------------------------
- NewBitMap() Creates bit image and inits the fields of the bitmap...
- ------------------------------------------------------------------------*/
-
- Boolean NewBitMap(BitMap *TheMap, Rect *TheRect)
- {
- long rb;
- Ptr ba;
-
- rb = ((TheRect->right - TheRect->left + 15) / 16) * 2;
- ba = NewPtr(rb * (TheRect->bottom - TheRect->top));
- if( MemError() == noErr)
- {
- TheMap->rowBytes = rb;
- TheMap->baseAddr = ba;
- TheMap->bounds = *TheRect;
- return(true);
- }
- else
- return(false);
- }
-
- /*-------------------------------------------------------------------------
- CenterRect() Centers theRect over thePt...
- --------------------------------------------------------------------------*/
- void CenterRect(Rect *theRect, Point *thePt)
- {
- /* First home theRect... */
-
- OffsetRect(theRect, -theRect->left, -theRect->top);
-
- /* ...then center it over thePt */
-
-
- thePt->h = thePt->h - (theRect->right / 2);
- thePt->v = thePt->v - (theRect->bottom / 2);
- OffsetRect(theRect, thePt->h, thePt->v);
- }
-
- /*-------------------------------------------------------------------------
- Center() Returns the center of the rect
- --------------------------------------------------------------------------*/
- Point Center(Rect *theRect)
- {
- Point pt;
-
- pt.h = theRect->left + ((theRect->right - theRect->left) / 2);
- pt.v = theRect->top + ((theRect->bottom - theRect->top) / 2);
- return(pt);
- }
-
-
- /*-------------------------------------------------------------------------
- These routines are from DTS Utilities
- --------------------------------------------------------------------------*/
- short NumToolboxTraps(void)
- {
- if (NGetTrapAddress(_InitGraf, ToolTrap) == NGetTrapAddress(0xAA6E, ToolTrap))
- return (0x200);
- else
- return (0x400);
- }
-
- TrapType GetTrapType(short theTrap)
- {
- /* OS traps start with A0, Tool with A8 or AA. */
- if ((theTrap & 0x0800) == 0) /* per D.A. */
- return (OSTrap);
- else
- return (ToolTrap);
- }
-
- Boolean TrapAvailable(short theTrap)
- {
- TrapType theTrapType;
-
- theTrapType = GetTrapType(theTrap);
- if ((theTrapType == ToolTrap) && ((theTrap &= 0x07FF) >= NumToolboxTraps()))
- theTrap = _Unimplemented;
-
- return (NGetTrapAddress(_Unimplemented, ToolTrap) != NGetTrapAddress(theTrap,
- theTrapType));
- }
-
- // Catenate 2 Str255s
- void pcat255(StringPtr d, StringPtr s)
- {
- short i, j;
-
- if (((j = s[0]) + d[0]) > 255)
- j = 255 - d[0];
- /* Limit dest string to 255. */
-
- for (i = 0; i < j;) d[++d[0]] = s[++i];
- }
-
- // Catenate 2 Str63s
- void pcat63(StringPtr d, StringPtr s)
- {
- short i, j;
-
- if (((j = s[0]) + d[0]) > 63)
- j = 63 - d[0];
- /* Limit dest string to 63. */
-
- for (i = 0; i < j;) d[++d[0]] = s[++i];
- }
-
- // Catenate 2 Strs, but make the result <= 31 characters, with s guaranteed to
- // be at the end
- void AppendStr31(StringPtr d, StringPtr s)
- {
- short i, addLength = s[0], posIndex = d[0];
-
- // Keep suffix a reasonable length
- if(addLength > 20)
- addLength = 20;
-
- // Limit ending srting to 31
- if ((posIndex + addLength) > 31)
- posIndex = 31 - addLength;
-
- // Append
- for (i = 0; i < addLength;) d[++posIndex] = s[++i];
- d[0] = posIndex; // remember new length
- }
-
-